<?php
class Searcher
{
	private $or;
	private $and;
	private $less;
	private $bigger;
	public function Searcher($or=array(),$and=array())
	{
		$this->or = $or;
		$this->and = $and;	
	}
	public function Where()
	{
		$ret = 
		implode(' OR ',$this->PreImplodeQuery($this->or)).
		implode(' AND ',$this->PreImplodeQuery($this->and));
		if(strlen(trim($ret)) < 3) return ' 1 ';
		return $ret;
	}
	private function PreImplodeQuery($arr)
	{
		$temp = array();
		foreach($arr as $key =>$val)
		{
			if(is_array($val) && array_count_values($val))
			{//CHECKBOX
				for($i = 0; $i != sizeof($val); $i++){$val[$i] = Sql::QuoteValue($val[$i]);}
				$temp[] = Sql::QuoteColumn($key).' IN ('.implode(',',$val).') ';
			}
			else
			{
				$b = '=';
				
				$len = strlen($key)-1;
				if(($len < 1) || strlen(trim($val)) < 1) continue;
				if($key[$len]==1)
				{
					$b = '>';
				}
				else if($key[$len]==2) 
				{
					$b = '<';
				}
				$temp[] = Sql::QuoteColumn($key).$b.Sql::QuoteValue($val);
			}
		}
		return $temp;	
	}
}
?>